﻿(function () {
    console.log("include...");
    var lang = document.getElementById("mode").value;
    console.log(mode);
    var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        styleActiveLine: true,
        matchBrackets: true,
        theme: "default"
    });
    CodeMirror.modeURL = "/lib/codemirror/mode/%N/%N.js";
    var val = lang, m, mode, spec;
    if (m = /.+\.([^.]+)$/.exec(val)) {
        var info = CodeMirror.findModeByExtension(m[1]);
        if (info) {
            mode = info.mode;
            spec = info.mime;
        }
    } else if (/\//.test(val)) {
        var info = CodeMirror.findModeByMIME(val);
        if (info) {
            mode = info.mode;
            spec = val;
        }
    } else {
        mode = spec = val;
    }
    if (mode) {
        editor.setOption("mode", spec);
        CodeMirror.autoLoadMode(editor, mode);
        console.log(spec + "_" + mode);
    }

    //editor.setOption("mode", spec);
    //CodeMirror.autoLoadMode(editor, mode);
})();